<template>
	<view>
		<u-button type="primary" text="修改信息" @click="toChange" v-if="user.Roles.indexOf('管理员角色')!=-1 || user.Roles.indexOf('公司领导角色')!=-1
		|| user.Roles.indexOf('部门领导角色')!=-1 || user.Roles.indexOf('分公司副总')!=-1 || user.Roles.indexOf('分管领导')!=-1
		|| user.Roles.indexOf('部门内项目部审批人')!=-1 || insuranceData.CreatorId == user.Id || user.Roles.indexOf('车辆管理员')!=-1"></u-button>
		<u-collapse ref='coll' :value="['1','2']">
			<u-collapse-item name="1" title="信息" icon="order">
				<u-cell-group>
					<u-cell title="车辆名称" :use-label-slot="true">
						<span slot="label" class="cell-label">{{carData.Name}}</span>
					</u-cell>
					<u-cell title="车牌号" :use-label-slot="true">
						<span slot="label" class="cell-label">{{carData.CarNo || " "}}</span>
					</u-cell>
					<u-cell title="保险公司" :use-label-slot="true">
						<span slot="label" class="cell-label">{{insuranceData.InsuranceCompany || " "}}</span> 
					</u-cell>
					<u-cell title="保险种类" :use-label-slot="true">
						<span slot="label" class="cell-label">{{insuranceData.InsuranceType || " "}}</span>
					</u-cell>
					<u-cell title="保险金额(元)" :use-label-slot="true">
						<span slot="label" class="cell-label">{{insuranceData.InsuranceAmount || " "}}</span> 
					</u-cell>
					<u-cell title="车税(元)" :use-label-slot="true">
						<span slot="label" class="cell-label">{{insuranceData.InsuranceVehicleTax || " "}}</span> 
					</u-cell>
					<u-cell title="合计金额(元)" :use-label-slot="true">
						<span slot="label" class="cell-label">{{insuranceData.TotalAmount || " "}}</span> 
					</u-cell>
					<u-cell title="保险购买时间" :use-label-slot="true">
						<span slot="label" class="cell-label">{{insuranceData.InsuranceBuytime || " "}}</span> 
					</u-cell>
					<u-cell title="保险到期时间" :use-label-slot="true">
						<span slot="label" class="cell-label">{{insuranceData.InsuranceTimeout || " "}}</span> 
					</u-cell>
					<u-cell title="期限" :use-label-slot="true">
						<span slot="label" class="cell-label">{{insuranceData.InsurancePeriod || " "}}</span> 
					</u-cell>
					<u-cell title="办理人" :use-label-slot="true">
						<span slot="label" class="cell-label">{{insuranceData.Agent || " "}}</span> 
					</u-cell>
					<u-cell title="备注" :use-label-slot="true">
						<span slot="label" class="cell-label">{{insuranceData.Remark || " "}}</span>
					</u-cell>
				</u-cell-group>
			</u-collapse-item>
			<u-collapse-item name="2" title="附件照片" icon="https://project.gxrunxiang.com/cdn/image.png">
				<u-album :urls="imagesurls1"></u-album>
			</u-collapse-item>
		<u-button type="error" :plain="true" v-if="user.Roles.indexOf('管理员角色')!=-1 || user.Roles.indexOf('公司领导角色')!=-1 
		|| user.Roles.indexOf('部门领导角色')!=-1 || user.Roles.indexOf('分公司副总')!=-1 || user.Roles.indexOf('分管领导')!=-1
		|| user.Roles.indexOf('部门内项目部审批人')!=-1 || insuranceData.CreatorId == user.Id || user.Roles.indexOf('车辆管理员')!=-1"
			@click="delmodalShow = true">删除</u-button>
		</u-collapse>
		<u-toast ref="uToast"></u-toast>
		<u-modal :show="delmodalShow" title="提示" content='确认删除?' @confirm="del" :showCancelButton="true"
			confirmText="是" cancelText="否" @cancel="delmodalShow = false" :closeOnClickOverlay="true"
			@close="delmodalShow = false"></u-modal>
	</view>
</template>
<script>
	import {
		baseUrl
	} from '@/common/config.js'
	import {
		mapGetters
	} from 'vuex'
	import {
		getinsurancelist,
		getfilebyoutid,
		delinsurance
	} from '@/common/api.js'
	export default {
		data() {
			return {
				insuranceId: "",
				insuranceData: [],
				carData: [],
				creatorData: [],
				imagesurls1: [],
				modalShow: false,
				delmodalShow: false,
				user: {}
			}
		},
		onLoad(option) {
			this.user = JSON.parse(uni.getStorageSync("$userinfo"))
			this.insuranceId = option.Id
		},
		onShow(){
			this.getlist(this.insuranceId)
		},
		methods: {
			async getlist(id) {
				let para = {
					Parameters: [],
				}
				para.Parameters.push({
					FieldName: "Id",
					ConditionalType: "Equal",
					FieldValue: id
				})
				await getinsurancelist(para).then(res => {
					this.insuranceData = res.data[0]
					this.carData = res.data[0].Car
					this.creatorData = res.data[0].Creator
				})
				this.imagesurls1 = []
				getfilebyoutid(this.insuranceId).then(res => {
					for (var i = 0; i < res.length; i++) {
						if (res[i].MyType == '附件照片') {
							this.imagesurls1.push(`${baseUrl}/SysFile/download?id=${res[i].Id}`)
						}
					}
					setTimeout(() => {
							this.$refs.coll.init()
						},
					1000)
					console.log(this.imagesurls1);
				})
			},
			del(){
				let ids = []
				ids.push(this.insuranceId)
				delinsurance(ids).then((res) => {
					if (res == true)
						uni.navigateBack()
				})
			},
			toChange(){
				uni.navigateTo({
					url: "addinsurance?Id=" + this.insuranceId
				})
			}
		}
	}
</script>
<style>
	.cell-label {
		margin-top: 10px;
		font-size: 14px;
		color: #909193;
	}
</style>